﻿Public Class frmRank
    Public who As CareGiver
    Private Sub frmRank_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        With cboLevel.Items
            .Add("Guest")
            .Add("Caregiver")
            .Add("Supervisor")
            .Add("Stranded User")
            .Add("Administrator")
        End With

        Me.Icon = Icon.FromHandle(My.Resources.note.GetHicon)

        cboLevel.SelectedIndex = who.SecurityLevel
        Try
            txtFire.Text = My.Computer.FileSystem.ReadAllText(String.Format("id\logs\{0}_fire.log", who.SaveFile.Substring(who.SaveFile.LastIndexOf("\") + 1)))
        Catch ex As Exception

        End Try
    End Sub
    Private Sub cmdFire_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFire.Click
        If Not extend.CheckPermission(ACCESS_ADMINISTRATOR) Then
            MsgBox("You do not have permission to do this", MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, "Error")
            Exit Sub
        End If
        If txtFire.Text.Length < 32 Then
            MsgBox("Please use a more detailed reason for firing this caregiver.", MsgBoxStyle.OkOnly + MsgBoxStyle.Information, "Error")
            Exit Sub
        End If

        If who.SecurityLevel < ACCESS_CAREGIVER Then
            MsgBox("User is already fired", MsgBoxStyle.OkOnly + MsgBoxStyle.Exclamation, "Error")
            Exit Sub
        End If

        Dim f As New IO.FileStream(String.Format("id\logs\{0}_fire.log", who.SaveFile.Substring(who.SaveFile.LastIndexOf("\") + 1)), IO.FileMode.Create, IO.FileAccess.Write, IO.FileShare.None)

        f.Write(New System.Text.ASCIIEncoding().GetBytes(txtFire.Text), 0, txtFire.Text.Length)

        f.Close()

        who.SecurityLevel = ACCESS_GUEST
        extend.SaveUserData()
        Beep()
        Me.Close()
    End Sub
    Private Sub cmdChange_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdChange.Click
        If Not txtOne.Text.Equals(txtTwo.Text) Then
            MsgBox("Passwords do not match", MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, "Error")
            Exit Sub
        End If

        who.PasswordHash = extend.Base64Sha1(txtOne.Text)
        user_registry(extend.Base64Sha1(who.UserName)) = who.PasswordHash
        extend.SaveUserData()
    End Sub
    Private Sub cmdRank_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRank.Click
        who.SecurityLevel = cboLevel.SelectedIndex
        extend.SaveUserData()
    End Sub
End Class